package com.xy.modular.sys.service.impl;

import com.xy.framework.base.dao.IBaseDao;
import com.xy.framework.base.service.BaseServiceImpl;
import com.xy.framework.exceptions.ValidateParamException;
import com.xy.framework.util.uuid.UUIDUtils;
import com.xy.modular.sys.dao.RoleMapper;
import com.xy.modular.sys.dao.RoleMenuMapper;
import com.xy.modular.sys.entity.role.Role;
import com.xy.modular.sys.entity.role.RoleMenu;
import com.xy.modular.sys.service.IRoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("roleService")
public class RoleServiceImpl extends BaseServiceImpl<Role, String> implements IRoleService {

	@Resource
	private RoleMapper roleMapper;

	@Resource
	private RoleMenuMapper roleMenuMapper;

	@SuppressWarnings("rawtypes")
	@Override
	protected IBaseDao getBaseDao() {
		return this.roleMapper;
	}

	@Override
	public void validateEntity(Role e) throws ValidateParamException {
		// TODO Auto-generated method stub

	}

	@Override
	public void roleMenuUpdate(RoleMenu roleMenu) {
		roleMenuMapper.deleteById(roleMenu.getRoleId());
		String str[]=roleMenu.getMenuId().split(",");
		for (int i = 0; i < str.length; i++) {
			roleMenu.setId(UUIDUtils.UUID());
			roleMenu.setMenuId(str[i]);
			roleMenuMapper.save(roleMenu);
		}
	}
}
